package baseTest;

public class romanToInt {
    public static void main(String[] args) {
        System.out.println(process("MCMXCIV"));
    }
    public static int process(String s){
        int sum =0;
        for (int i = 0; i < s.length(); i++) {
            switch (s.charAt(i)){
                case 'I':
                    if (i<s.length()-1 && s.charAt(i+1) == 'V'){
                        sum += 5-1;
                        i++;
                    }else if (i<s.length()-1 && s.charAt(i+1) == 'X'){
                        sum+=10-1;
                        i++;
                    }else
                    sum++;
                    break;
                case 'V':
                    sum+=5;
                    break;
                case 'X':
                    if (i<s.length()-1 && s.charAt(i+1) == 'L'){
                        sum += 50-10;
                        i++;
                    }else if (i<s.length()-1 && s.charAt(i+1) == 'C'){
                        sum+=100-10;
                        i++;
                    }else
                    sum+=10;
                    break;
                case 'L':
                    sum+=50;
                    break;
                case 'C':
                    if (i<s.length()-1 && s.charAt(i+1) == 'D'){
                        sum += 500-100;
                        i++;
                    }else if (i<s.length()-1 && s.charAt(i+1) == 'M'){
                        sum+=1000-100;
                        i++;
                    }else
                    sum+=100;
                    break;
                case 'D':
                    sum+=500;
                    break;
                case 'M':
                    sum+=1000;
            }
        }
        return sum;
    }
}
